<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 实现简易的留言板 -todoList</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.13/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <h4>{{msg}}</h4>
        <hr>
        <p>展示留言</p>
        <ul>
            <li v-for="(l,i) in list">
                {{i}} -- {{l.title}}
                <button v-on:click="list.splice(i,1)">删除</button>
                <button v-on:click="change(l,i)">修改</button>
            </li>
        </ul>
        <hr>
        <p>添加留言</p>
        <p>
            <input type="text" v-model="word">
            <button v-on:click="addSome">点击添加留言</button>
        </p>
    </div>
</body>
<script>
    const vm = new Vue({
        el: "#app",
        data: {
            msg: "Vue 实现 todoList - 留言板",
            list: [
                {
                    title: "Vue 真的好简单"
                },
                {
                    title: "你要加油呀"
                },
                {
                    title: "坚持就是胜利"
                }
            ],
            word: "点这里增加啊"

        },
        methods: {
            change(item, index) {
                var value = window.prompt("更改框里面的内容", item.title)
                if (value) {
                    this.list.splice(index, 1, { title: value })
                }
            },
            addSome() {
                this.list.push({ title: this.word })
                this.word = ""
            }
        }
    })
</script>

</html>